package com.nf.health.app.activity.doctor_advice.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.Constants;
import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.activity.doctor_advice.adapter.DoctorAdviceByIdAdapter;
import com.nf.health.app.activity.doctor_advice.adapter.MedicinePrescriptionAdapter;
import com.nf.health.app.activity.doctor_advice.bean.AdviceDetail;
import com.nf.health.app.activity.doctor_advice.view.MyAdviceDetailQuestionLineaylayout;
import com.nf.health.app.customview.CustomScrollView;
import com.nf.health.app.customview.MyListView;
import com.nf.health.app.http.Act;
import com.nf.health.app.utils.ViewUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by fei on 2016/11/24.
 */

public class MyDoctorAdaviceDetailActivity   extends BaseActivity {
    private  String ID = "";
    @Bind(R.id.tv_doctoradvice_note)
    TextView tv_doctoradvice_note;
  /*  @Bind(R.id.mlv_byself_ask)
    MyListView mlv_byself_ask;*/
    @Bind(R.id.mlv_byself_medicine)
    MyListView mlv_byself_medicine;
    @Bind(R.id.cus_slv)
    CustomScrollView cus_slv;
    @Bind(R.id.ll_insten_question)
    LinearLayout ll_insten_question;
    @Bind(R.id.tv_result_forgindoctor)
    TextView tv_result_forgindoctor;
    @Bind(R.id.tv_result_middledoctor)
    TextView tv_result_middledoctor;
    @Bind(R.id.ll_remark)
    LinearLayout ll_remark;
    @Bind(R.id.tv_advice_medeachenie)
    TextView tv_advice_medeachenie;
    @Bind(R.id.tv_advice_aky_byself)
    TextView tv_advice_aky_byself;
    @Bind(R.id.tv_advice_result)
    TextView tv_advice_result;
    @Bind(R.id.tv_advice_mark)
    TextView tv_advice_mark;
    private DoctorAdviceByIdAdapter doctorAdviceByIdAdapter;
    private MedicinePrescriptionAdapter medicinePrescriptionAdapter;
    private List<AdviceDetail.QuestionListBean> datas = new ArrayList<>();
    private List<AdviceDetail.MedicationBean> medicineDescriptList = new ArrayList<>();
    private AdviceDetail adviceDetail;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleBar(R.layout.titlebar_base);
        setContent(R.layout.activity_adavicedetail);
        ButterKnife.bind(this);
        ViewUtil.setText(this, R.id.titlebar_title_tv, "医嘱");
        initListener();
        initView();

    }

    private void initListener() {

    }

    private void initView() {
        ID = getIntent().getStringExtra(Constants.DOCTOR_ADVICE_ID);
//        tv_advice_medeachenie.set
        ViewUtil.setTextImgBackground3(tv_advice_medeachenie,this, ViewUtil.TextMode.LEFT,0,R.drawable.iv_medition,15,50);
        ViewUtil.setTextImgBackground3(tv_advice_aky_byself,this, ViewUtil.TextMode.LEFT,0,R.drawable.iv_byself_ask,15,50);
        ViewUtil.setTextImgBackground3(tv_advice_mark,this, ViewUtil.TextMode.LEFT,0,R.drawable.iv_doctor_remark,15,50);
        ViewUtil.setTextImgBackground3(tv_advice_result,this, ViewUtil.TextMode.LEFT,0,R.drawable.iv_result_advice,15,50);
        tv_result_forgindoctor.setText("");
        tv_result_middledoctor.setText("");
    }
    @Override
    protected void onResume() {
        super.onResume();
        loadData(ID);
    }
    private void loadData(String id){
        provider.getDoctorAdviceById(id);
    }
    @Override
    public void handleActionSuccess(String actionName, Object object) {
        super.handleActionSuccess(actionName, object);
        switch (actionName){
            case Act.Flag.GETDOCTORADVICEBYID_FLAG:
                adviceDetail    = (AdviceDetail) object;
                if(adviceDetail != null){
                    datas = adviceDetail.getQuestionList();
                    medicineDescriptList = adviceDetail.getMedication();
                    //问题列表
                     /*if(doctorAdviceByIdAdapter == null){
                        doctorAdviceByIdAdapter = new DoctorAdviceByIdAdapter(MyDoctorAdaviceDetailActivity.this,datas);
                        mlv_byself_ask.setAdapter(doctorAdviceByIdAdapter);
                        doctorAdviceByIdAdapter.regisitOnMyClickListener(new OnMyClickListener() {
                            @Override
                            public void onClick(int position, String flag) {
                                cus_slv.invalidate();
                            }
                        });
                    }else{
                        doctorAdviceByIdAdapter.setAdapterDataChanged(datas);
                    }*/
                    ll_insten_question.removeAllViews();
                    if(datas != null){
                        for (int i = 0; i < datas.size(); i++) {
                            AdviceDetail.QuestionListBean questionListBean = datas.get(i);
                            if(i == 0){
                                questionListBean.setOpenStatuis(true);
                            }
                            MyAdviceDetailQuestionLineaylayout my = new MyAdviceDetailQuestionLineaylayout(MyDoctorAdaviceDetailActivity.this,questionListBean);
                            ll_insten_question.addView(my);
                        }
                    }
                    //用药处方列表
                    if(medicinePrescriptionAdapter == null){
                        medicinePrescriptionAdapter = new MedicinePrescriptionAdapter(MyDoctorAdaviceDetailActivity.this,medicineDescriptList);
                        mlv_byself_medicine.setAdapter(medicinePrescriptionAdapter);
                    }else{
                        medicinePrescriptionAdapter.setAdapterDataChanged(medicineDescriptList);
                    }

                    if(TextUtils.isEmpty(adviceDetail.getRemarks())){
                        tv_doctoradvice_note.setVisibility(View.GONE);
                        ll_remark.setVisibility(View.GONE);
                    }else{
                        ll_remark.setVisibility(View.VISIBLE);
                        tv_doctoradvice_note.setVisibility(View.VISIBLE);
                        tv_doctoradvice_note.setText(""+adviceDetail.getRemarks());
                    }
                    tv_result_forgindoctor.setText(TextUtils.isEmpty(adviceDetail.getWesterndiagnose()) ? "":""+adviceDetail.getWesterndiagnose());
                    tv_result_middledoctor.setText(TextUtils.isEmpty(adviceDetail.getChinesediagnose()) ? "":""+adviceDetail.getChinesediagnose());
                }
                break;
        }
    }

}
